package nl.saxion.act.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nl.saxion.act.dao.AuctionDAO;
import nl.saxion.act.dao.CatagoryDAO;
import nl.saxion.act.db.DatabaseManager;
import nl.saxion.act.wt.Auction;

/**
 * Servlet implementation class AuctionServlet
 */
public class AuctionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private DatabaseManager dbMan;
	private ServletContext context;
       
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AuctionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public void init() throws ServletException {
    	context = this.getServletContext();
    	dbMan = (DatabaseManager) context.getAttribute("dbMan");   	
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int auctionID = Integer.parseInt( request.getParameter("ID") );
		AuctionDAO a = new AuctionDAO(dbMan);
		Auction auction = a.getAuctionID(auctionID);
		request.setAttribute("auction", auction ) ;
		
		CatagoryDAO catagory = new CatagoryDAO(dbMan);
		request.setAttribute("catagories", catagory.getAllCatagory() );
		
		RequestDispatcher view = context.getRequestDispatcher("/fullInfo.jsp");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
